package com.tvsinfo.jdk.demo.case6_higher_order_function.order;


import lombok.val;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public enum OrderTypeEnum {
    DINNER(101, "点餐-正餐", 1, "正餐"),
    FAST_MEAL_QUE(102, "点餐-快餐-排队取餐", 1, "点餐"),
    FAST_MEAL_DESK(103, "点餐-快餐-桌台取餐", 1, "快餐"),
    FAST_PAY_ORDER(104, "点餐-秒付", 104, "秒付"),

    TAKE_OUT_ORDER(201, "外卖-商户配送", 2, "外卖"),

    //优惠买单
    DISCOUNT_ORDER(301, "买单收款", 4, "买单收款"),
    POS_ORDER(401, "POS", 3, "POS"),
    APP_RECEIPT_ORDER(501, "APP收款", 16, "APP收款"),

    POINT_MALL_ORDER_REAL(1001, "积分商城-实物", 9, "积分商城"),
    POINT_MALL_ORDER_CARD(1002, "积分商城-卡券", 9, "积分商城"),

    BOOKING_ORDER(1101, "预约预订", 20, "预约预订"),

    PAY_MEMBER_CARD(1201, "会员开卡-付费", 13, "付费会员卡"),
    DEPOSIT_MEMBER_CARD(1202, "会员开卡-储值", 15, "储值开卡"),
    MEMBER_DEPOSIT_TYPE(1301, "会员充值", 14, "会员充值");
    private Integer key;
    private String desc;
    private Integer oldType;
    private String productDesc;

    OrderTypeEnum(Integer key, String desc, Integer oldType, String productDesc) {
        this.key = key;
        this.desc = desc;
        this.oldType = oldType;
        this.productDesc = productDesc;
    }

    private static final Map<Integer, List<OrderTypeEnum>> oldOrderTypeEnumMap = new ConcurrentHashMap<>();
    static {
        OrderTypeEnum[] arr$ = values();
        int len$ = arr$.length;
        for (int i$ = 0; i$ < len$; ++i$) {
            OrderTypeEnum orderType = arr$[i$];
            val orderStatusEnums = oldOrderTypeEnumMap.get(orderType.oldType);
            if (null == orderStatusEnums) {
                oldOrderTypeEnumMap.put(orderType.oldType, new ArrayList<>());
            }
            oldOrderTypeEnumMap.get(orderType.oldType).add(orderType);
        }
    }

    /**
     * 根据老的type获取新的type
     * create by Ruyi.Song on 2018/8/16 15:36
     */
    public static List<OrderTypeEnum> getByOldType(Integer oldType) {
        if (null == oldType) {
            return null;
        }
        List<OrderTypeEnum> orderTypeEnum = oldOrderTypeEnumMap.get(oldType);
        return orderTypeEnum;
    }

    public Integer getKey() {
        return this.key;
    }

}
